package com.example.teamtribe.database;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

import org.litepal.crud.DataSupport;

/**
 * Created by lenovo on 2018/6/3.
 */

public class Media extends DataSupport implements Parcelable, Comparable<Media> {

    private int id;
    private int realId;
    private String name;
    private int teamId;
    private String createTime;
    private String cover;
    private String description;
    private int type;

    public Media() {
    }

    @Override
    public int compareTo(@NonNull Media o) {
        return o.realId - realId > 0 ? 1 : -1;
    }

    @Override
    public String toString() {
        return "Media{" +
                "id=" + id +
                ", realId=" + realId +
                ", name='" + name + '\'' +
                ", teamId=" + teamId +
                ", createTime='" + createTime + '\'' +
                ", cover='" + cover + '\'' +
                ", description='" + description + '\'' +
                ", type=" + type +
                '}';
    }

    public synchronized boolean saveOrUpdate() {
        return saveOrUpdate("realId = ?", realId + "");
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Media) {
            Media media = (Media) obj;
            return this.realId == media.realId;
        }
        return false;
    }
    @Override
    public int hashCode() {
        return realId;
    }

    public int getId() {return id;}

    public void setId(int id) {this.id = id;}

    public int getRealId() {return realId;}

    public void setRealId(int realId) {this.realId = realId;}

    public int getTeamId() {return teamId;}

    public void setTeamId(int teamId) {this.teamId = teamId;}

    public String getCreateTime() {return createTime;}

    public void setCreateTime(String createTime) {this.createTime = createTime;}

    public String getName() {return name;}

    public void setName(String name) {this.name = name;}

    public String getCover() {return cover;}

    public void setCover(String cover) {this.cover = cover;}

    public String getDescription() {return description;}

    public void setDescription(String description) {this.description = description;}

    public int getType() {return type;}

    public void setType(int type) {this.type = type;}

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeInt(this.realId);
        dest.writeString(this.name);
        dest.writeInt(this.teamId);
        dest.writeString(this.createTime);
        dest.writeString(this.cover);
        dest.writeString(this.description);
        dest.writeInt(this.type);
    }

    protected Media(Parcel in) {
        this.id = in.readInt();
        this.realId = in.readInt();
        this.name = in.readString();
        this.teamId = in.readInt();
        this.createTime = in.readString();
        this.cover = in.readString();
        this.description = in.readString();
        this.type = in.readInt();
    }

    public static final Creator<Media> CREATOR = new Creator<Media>() {
        @Override
        public Media createFromParcel(Parcel source) {
            return new Media(source);
        }

        @Override
        public Media[] newArray(int size) {
            return new Media[size];
        }
    };
}
